<template>
  <view class="page-wraper bg-gray">
    <view class="page-wraper-body flex-col align-items-center justify-center" v-if="show">
      <view class="page-wraper-simview">
        <view class="page-wraper-simviewtitle f-18 bold">面试邀请函</view>
        <view class="divider"></view>
        <view class="mt-24">尊敬的先生/女士：</view>
        <view class="mt-24">感谢您应聘<text  class="bold">{{ data.company_name }}</text>的<text class="bold">{{ data.job_name }}</text>职位。经过对您简历的认真评估，我们诚挚地邀请您参加面试。</view>
        
        <view class="flex-row mt-24">
          <view class="bold">面试岗位:</view>
          <view>{{ data.job_name }}</view>
        </view>
        <view class="flex-row mt-24">
          <view class="bold">截至日期:</view>
          <view>{{ data.endTime }}</view>
        </view>
        <view class="flex-row mt-24">
          <view class="bold">面试方式:</view>
          <view>线上AI面试</view>
        </view>
        <view class="flex-row mt-24">
          <view class="bold">面试时长:</view>
          <view>{{ data.countdown ? parseInt(data.countdown / 60) : '--' }}分钟</view>
        </view>
        <view class="mt-48 flex-row align-items-center mb-48 justify-center">
            <view class="mr-12" @click="handerject(0)">
              <pk-btn size="small" type="danger">拒绝</pk-btn>
            </view>
            <view @click="handerject(1)">
              <pk-btn size="small" type="success">接受</pk-btn>
            </view>
        </view>
        <view class="divider"></view>
        <view class="mt-48 page-wraper-simviewfooter">
          <text class="pr-12">{{ data.company_name }}</text> <text>人力资源部</text>
          <view class="mt-24">{{time}}</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
  import { getBasicInfo, scheduleInterview } from '@/api/api'
  import { ref } from 'vue'
  import { onShow, onLoad } from '@dcloudio/uni-app'
  import { useInfoStore } from '@/store/info'
  import { getTimeYearStr } from '@/utils/utils'
  const userInfo = useInfoStore()
  const data = ref({})
  const time = ref("")
  const invitationId = ref('')
  const show = ref(false)
  
  onLoad((e) => {
    invitationId.value = e.key || ''
    
  })

  onShow(() => {
    getInit()
    time.value = getTimeYearStr(new Date().getTime()/ 1000, 'date', ['年', '月', '日'])
    gotvInerview(1)
  })

  const getInit = () => {
    if (!userInfo.token) {
      return
    }
    getBasicInfo({
      key: invitationId.value
    }).then(res => {
      data.value = {
        ...res.data,
        endTime: getTimeYearStr((new Date().getTime() + res.data.delay_days * 86400000)/ 1000, 'time',)
      }
    })
  }

  const gotvInerview = (is_accept) => {
    scheduleInterview({
      invitation_id: invitationId.value,
      is_accept: is_accept
    }).then(res => {
      setTimeout(() => {
        uni.switchTab({
          url: '/pages/interview/index'
        });
      }, 2500)
    })
  }

  const handerject = (e) => {
    if (!userInfo.token) {
      return
    }
    gotvInerview(e)
  }
</script>

<style lang="scss" scoped>
.page-wraper{
  font-size: 28rpx;
  &-body{
    width: 100vw;
    height: 100vh;
    overflow: hidden;
  }
  &-simview{
    border: #ddd 1rpx solid;
    padding: 32rpx;
    border-radius: 24rpx;
    background: #fff;
    width: 80%;
    margin: 0 10%;
  }
  &-simviewtitle{
    text-align: center;
    padding-bottom: 32rpx;
  }
  &-simviewfooter{
    text-align:right
  }
}
</style>